package com.dayuanit.dy15.atm.controller;

import com.dayuanit.dy15.atm.service.UserDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class ViewController extends BaseController {

    @Autowired
    private UserDetailService userDetailService;

    @RequestMapping(value = {"/", "/toLogin"})
    public String welcome() {
        return "login";
    }

    @RequestMapping("/toRegist")
    public String toRegist() {
        return "sign-up";
    }

    @RequestMapping("/user/toHome")
    public String toHome() {
        return "index";
    }

    @RequestMapping("/user/toOpenaccount")
    public String toOpenaccount() {
        return "openaccount";
    }

    @RequestMapping("/user/toDeposit")
    public String toDeposit() {
        return "deposit";
    }

    @RequestMapping("/user/toDraw")
    public String toDraw() {
        return "draw";
    }

    @RequestMapping("/user/toTransfer")
    public String toTransfer() {
        return "transfer";
    }

    @RequestMapping("/user/toFlow")
    public String toFlow() {
        return "flow";
    }

    @RequestMapping("/userDetail/toEmail")
    public String toEmail() {
        return "email";
    }

    @RequestMapping("/userDetail/toForgetPwd.html")
    public String toForgetPwd() {
        return "forgetPwd";
    }

    @RequestMapping("/user/toResetPwd")
    public String toResetpwd() {
        return "resetPwd";
    }

    @RequestMapping("/userDetail/toRetrievePwd")
    public String toRetrievePwd(String email, long expireTime, String sign, HttpSession session) {
        session.setAttribute("email", email);
        session.setAttribute("expireTime", expireTime);
        session.setAttribute("sign", sign);
        return "retrievePwd";
    }

    @RequestMapping("/userDetail/activeEmail")
    public String activeEmail(String email, long expireTime, String sign, HttpServletRequest request) {
        try {
            userDetailService.activeEmail(email,expireTime, sign, getUserId(request));
            return "email";
        } catch (Exception e) {
            e.printStackTrace();
            request.setAttribute("errorMessage", e.getMessage());
            return "500";
        }
    }


    @RequestMapping("/wx/toBind")
    public String toBind() {
        return "wxBind";
    }
}
